using System;
using System.Collections.ObjectModel;
using System.Windows;
using WPFPractice.UserControls.DynamicColumnTable;
using WPFPractice.Utils;
using WPFPractice.ViewModels;
using WPFTemplateLib.Controls.WpfToast;

namespace WPFPractice.Windows
{
	public partial class WinDynamicColumnTable : Window
	{
		public WinDynamicColumnTable()
		{
			InitializeComponent();
			DataContext = new DynamicColumnTableViewModel();
		}

		private void TableEventHelper_OnContentVerticalScrolled(object sender, ScrolledEventArgs e)
		{
			if(e.Source.Equals(table1))
			{
				table2.cell_scroll.ScrollToVerticalOffset(e.Offset);
			}

			if(e.Source.Equals(table2))
			{
				table1.cell_scroll.ScrollToVerticalOffset(e.Offset);
			}
		}

		private void Table2_OnColumnHeaderCheckChanged(object sender, CheckChangedEventArgs e)
		{
			ToastHelper.ToastToScreen($"Tag:{e.Tag}, IsChecked:{e.IsChecked}");
		}
	}
}

namespace WPFPractice.ViewModels
{
	public class DynamicColumnTableViewModel : MyViewModelBase
	{
		#region 绑定

		public DataTable DataTable { get; set; }

		#endregion

		#region 方法

		protected override void InitDataAfterConstruction()
		{
			Console.WriteLine("演示动态列表格");

			DataTable = new DataTable()
			{
				Columns = new ObservableCollection<TableColumn>()
				{
					new ("序号"){CanSelected = false}, new ("时间"){/*Width = 300*/}, new ("数字"), new ("第四列"),
				},
				Rows = new ObservableCollection<TableRow>()
				{
					new () { Cells = new () { new (1), new (DateTime.Now), new (34.51), new ("什么") } },
					new () { Cells = new () { new (2), new (DateTime.Now), new (40.522), new ("你好呀") } },
					new () { Cells = new () { new (3), new (DateTime.Now), new (39.53333), new ("我是谁") } },
					new () { Cells = new () { new (4), new (DateTime.Now), new (4.545), new ("哈哈哈") } },
					new () { Cells = new () { new (5), new (DateTime.Now), new (3.534), new ("嘿嘿嘿") } },
					new () { Cells = new () { new (6), new (DateTime.Now), new (39), new ("发发发") } },
					new () { Cells = new () { new (7), new (DateTime.Now), new (56.9), new ("打电话叫多方的发光时代") } },
					new () { Cells = new () { new (8), new (DateTime.Now), new (4.6789), new ("打道回府发货") } },
					new () { Cells = new () { new (9), new (DateTime.Now), new (145), new ("阿萨德覅的覅哦") } },
					new () { Cells = new () { new (10), new (DateTime.Now), new (27), new ("阿斯顿福建很尬") } },
				}
			};
		}

		#endregion
	}
}
